/*
在不改变其原有的结构和功能为对象添加新功能的模式其实就叫做装饰器模式
最直观地就是我们买房后的装修
装饰比继承更加灵活,可以实现装饰者和被装饰者之间松耦合
被装饰者可以使用装饰者动态地增加和撤销功能
*/
abstract class Shape {
  abstract draw(): void;
}
class Circle extends Shape {
  draw() {
    console.log('绘制圆形')
  }
}
class Rectangle extends Shape {
  draw() {
    console.log('绘制矩形')
  }
}
class Star extends Shape {
  draw() {
    console.log('绘制五角星')
  }
}
//装饰器模式的
abstract class ColorfulShape extends Shape {
  constructor(public shape: Shape) {
    super()
  }
  abstract draw(): void;
}
class RedColorfulShape extends ColorfulShape {
  draw() {
    this.shape.draw()
    console.log('把边框涂成红色')
  }
}
class GreenColorfulShape extends ColorfulShape {
  draw() {
    this.shape.draw()
    console.log('把边框涂成绿色')
  }
}
class YellowColorfulShape extends ColorfulShape {
  draw() {
    this.shape.draw()
    console.log('把边框涂成黄色')
  }
}
// 画一个红色的圆形
const redColorfulShape = new RedColorfulShape(new Circle())
redColorfulShape.draw()

const greenColorfulShape = new GreenColorfulShape(new Rectangle())
greenColorfulShape.draw()

const yellowColorfulShape = new YellowColorfulShape(new Star())
yellowColorfulShape.draw()
